home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / dos / read.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  109 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: read.c,v 1.5 1996/10/24 15:50:35 aros Exp $
  4.     $Log: read.c,v $
  5.     Revision 1.5  1996/10/24 15:50:35  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.4  1996/09/13 17:50:08  digulla
  9.     Use IPTR
  10.  
  11.     Revision 1.3  1996/08/13 13:52:50  digulla
  12.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  13.     Replaced AROS_LA by AROS_LHA
  14.  
  15.     Revision 1.2  1996/08/01 17:40:56  digulla
  16.     Added standard header for all files
  17.  
  18.     Desc:
  19.     Lang: english
  20. */
  21. #include <clib/exec_protos.h>
  22. #include <dos/dosextens.h>
  23. #include <dos/filesystem.h>
  24. #include "dos_intern.h"
  25.  
  26. /*****************************************************************************
  27.  
  28.     NAME */
  29.     #include <clib/dos_protos.h>
  30.  
  31.     AROS_LH3(LONG, Read,
  32.  
  33. /*  SYNOPSIS */
  34.     AROS_LHA(BPTR, file,   D1),
  35.     AROS_LHA(APTR, buffer, D2),
  36.     AROS_LHA(LONG, length, D3),
  37.  
  38. /*  LOCATION */
  39.     struct DosLibrary *, DOSBase, 7, Dos)
  40.  
  41. /*  FUNCTION
  42.     Read some data from a given file. The request is directly
  43.     given to the filesystem - no buffering is involved. For
  44.     small amounts of data it's probably better to use the
  45.     buffered I/O routines.
  46.  
  47.     INPUTS
  48.     file   - filehandle
  49.     buffer - pointer to buffer for the data
  50.     length - number of bytes to read. The filesystem is
  51.          advised to try to fulfill the request as good
  52.          as possible.
  53.  
  54.     RESULT
  55.     The number of bytes actually read, 0 if the end of the
  56.     file was reached, -1 if an error happened. IoErr() will
  57.     give additional information in that case.
  58.  
  59.     NOTES
  60.  
  61.     EXAMPLE
  62.  
  63.     BUGS
  64.  
  65.     SEE ALSO
  66.  
  67.     INTERNALS
  68.  
  69.     HISTORY
  70.     29-10-95    digulla automatically created from
  71.                 dos_lib.fd and clib/dos_protos.h
  72.  
  73. *****************************************************************************/
  74. {
  75.     AROS_LIBFUNC_INIT
  76.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  77.  
  78.     /* Get pointer to filehandle */
  79.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  80.  
  81.     /* Get pointer to process structure */
  82.     struct Process *me=(struct Process *)FindTask(NULL);
  83.  
  84.     /* Get pointer to I/O request. Use stackspace for now. */
  85.     struct IOFileSys io,*iofs=&io;
  86.  
  87.     /* Prepare I/O request. */
  88.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  89.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  90.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  91.     iofs->IOFS.io_Device =fh->fh_Device;
  92.     iofs->IOFS.io_Unit     =fh->fh_Unit;
  93.     iofs->IOFS.io_Command=FSA_READ;
  94.     iofs->IOFS.io_Flags  =0;
  95.     iofs->io_Args[0]=(IPTR)buffer;
  96.     iofs->io_Args[1]=length;
  97.  
  98.     /* Send the request. */
  99.     DoIO(&iofs->IOFS);
  100.  
  101.     /* Set error code and return */
  102.     if((me->pr_Result2=iofs->io_DosError))
  103.     return -1;
  104.     else
  105.     return iofs->io_Args[1];
  106.  
  107.     AROS_LIBFUNC_EXIT
  108. } /* Read */
  109.